home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 127 / PC Guia 127.iso / Software / Produtividade / OpenOffice.org 2.0.1 / openofficeorg2.cab / table1.xsl < prev    next >
Extensible Markup Language  |  2005-11-14  |  33KB  |  803 lines

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3.  
  4.    $RCSfile: table.xsl,v $
  5.  
  6.    $Revision: 1.5 $
  7.  
  8.    last change: $Author: rt $ $Date: 2005/11/10 16:53:23 $
  9.  
  10.     The Contents of this file are made available subject to
  11.     the terms of GNU Lesser General Public License Version 2.1.
  12.  
  13.  
  14.       GNU Lesser General Public License Version 2.1
  15.       =============================================
  16.       Copyright 2005 by Sun Microsystems, Inc.
  17.       901 San Antonio Road, Palo Alto, CA 94303, USA
  18.  
  19.       This library is free software; you can redistribute it and/or
  20.       modify it under the terms of the GNU Lesser General Public
  21.       License version 2.1, as published by the Free Software Foundation.
  22.  
  23.       This library is distributed in the hope that it will be useful,
  24.       but WITHOUT ANY WARRANTY; without even the implied warranty of
  25.       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  26.       Lesser General Public License for more details.
  27.  
  28.       You should have received a copy of the GNU Lesser General Public
  29.       License along with this library; if not, write to the Free Software
  30.       Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  31.       MA  02111-1307  USA
  32.  
  33. -->
  34. <xsl:stylesheet version="1.0"
  35.     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  36.     xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
  37.     xmlns:config="urn:oasis:names:tc:opendocument:xmlns:config:1.0"
  38.     xmlns:dc="http://purl.org/dc/elements/1.1/"
  39.     xmlns:dom="http://www.w3.org/2001/xml-events"
  40.     xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
  41.     xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
  42.     xmlns:fo="urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0"
  43.     xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
  44.     xmlns:math="http://www.w3.org/1998/Math/MathML"
  45.     xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
  46.     xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
  47.     xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
  48.     xmlns:ooo="http://openoffice.org/2004/office"
  49.     xmlns:oooc="http://openoffice.org/2004/calc"
  50.     xmlns:ooow="http://openoffice.org/2004/writer"
  51.     xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
  52.     xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
  53.     xmlns:svg="urn:oasis:names:tc:opendocument:xmlns:svg-compatible:1.0"
  54.     xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
  55.     xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
  56.     xmlns:xlink="http://www.w3.org/1999/xlink"
  57.     xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:c="urn:schemas-microsoft-com:office:component:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x2="http://schemas.microsoft.com/office/excel/2003/xml" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  58.     exclude-result-prefixes="chart config dc dom dr3d draw fo form math meta number office ooo oooc ooow script style svg table text xlink">
  59.  
  60.  
  61.     <!-- ************** -->
  62.     <!-- *** Table  *** -->
  63.     <!-- ************** -->
  64.  
  65.     <xsl:template match="table:table" name="table:table">
  66.         <xsl:element name="Table">
  67.             <xsl:apply-templates select="@table:style-name" />
  68.  
  69.             <!-- find all columns in the table -->
  70.             <xsl:variable name="columnNodes" select="descendant::table:table-column" />
  71.  
  72.             <!-- calculate the overall column amount -->
  73.             <xsl:variable name="maxColumnNo">
  74.                 <xsl:choose>
  75.                     <xsl:when test="$columnNodes/@table:number-columns-repeated">
  76.                         <xsl:value-of select="count($columnNodes)
  77.                                             + sum($columnNodes/@table:number-columns-repeated)
  78.                                             - count($columnNodes/@table:number-columns-repeated)" />
  79.                     </xsl:when>
  80.                     <xsl:otherwise>
  81.                         <xsl:value-of select="count($columnNodes)"/>
  82.                     </xsl:otherwise>
  83.                 </xsl:choose>
  84.             </xsl:variable>
  85.             <!-- create columns -->
  86.             <xsl:apply-templates select="$columnNodes[1]">
  87.                 <xsl:with-param name="columnNodes"  select="$columnNodes" />
  88.                 <xsl:with-param name="maxColumnNo"  select="$maxColumnNo" />
  89.             </xsl:apply-templates>
  90.  
  91.             <!-- create rows -->
  92.             <xsl:call-template name="optimized-row-handling">
  93.                 <xsl:with-param name="rowNodes"      select="descendant::table:table-row" />
  94.             </xsl:call-template>
  95.         </xsl:element>
  96.     </xsl:template>
  97.  
  98.  
  99.     <!-- **************** -->
  100.     <!-- *** Columns  *** -->
  101.     <!-- **************** -->
  102.  
  103.     <xsl:template match="table:table-column">
  104.         <xsl:param name="columnNodes"  />
  105.         <xsl:param name="currentColumnNumber" select="1" />
  106.         <xsl:param name="setIndex" select="false()" />
  107.         <xsl:param name="maxColumnNo" />
  108.  
  109.         <xsl:element name="Column">
  110.             <xsl:if test="@table:default-cell-style-name">
  111.                 <xsl:attribute name="ss:StyleID"><xsl:value-of select="@table:default-cell-style-name"/></xsl:attribute>
  112.             </xsl:if>
  113.  
  114.             <xsl:if test="@table:visibility = 'collapse' or @table:visibility = 'filter'">
  115.                 <xsl:attribute name="ss:Hidden">1</xsl:attribute>
  116.             </xsl:if>
  117.  
  118.             <xsl:if test="@table:number-columns-repeated">
  119.                 <xsl:attribute name="ss:Span">
  120.                     <xsl:value-of select="@table:number-columns-repeated - 1" />
  121.                 </xsl:attribute>
  122.             </xsl:if>
  123.  
  124.            <xsl:if test="$setIndex">
  125.                 <xsl:attribute name="ss:Index">
  126.                     <xsl:value-of select="$currentColumnNumber" />
  127.                 </xsl:attribute>
  128.             </xsl:if>
  129.  
  130.             <xsl:choose>
  131.                 <xsl:when test="@style:use-optimal-column-width = 'true'">
  132.                     <xsl:attribute name="ss:AutoFitWidth">1</xsl:attribute>
  133.                 </xsl:when>
  134.                 <xsl:otherwise>
  135.                     <xsl:variable name="width" select="key('styles', @table:style-name)/style:table-column-properties/@style:column-width" />
  136.                     <xsl:if test="$width">
  137.                         <xsl:attribute name="ss:Width">
  138.                             <!-- using the absolute width in point -->
  139.                             <xsl:call-template name="convert2pt">
  140.                                 <xsl:with-param name="value" select="$width" />
  141.                             </xsl:call-template>
  142.                         </xsl:attribute>
  143.                     </xsl:if>
  144.                 </xsl:otherwise>
  145.             </xsl:choose>
  146.  
  147.             <xsl:if test="@table:number-columns-repeated">
  148.                 <xsl:attribute name="ss:Span">
  149.                     <xsl:value-of select="@table:number-columns-repeated - 1" />
  150.                 </xsl:attribute>
  151.             </xsl:if>
  152.         </xsl:element>
  153.  
  154.         <xsl:variable name="columnNumber">
  155.             <xsl:choose>
  156.                 <xsl:when test="@table:number-columns-repeated">
  157.                     <xsl:value-of select="$currentColumnNumber + @table:number-columns-repeated"/>
  158.                 </xsl:when>
  159.                 <xsl:otherwise>
  160.                     <xsl:value-of select="$currentColumnNumber"/>
  161.                </xsl:otherwise>
  162.            </xsl:choose>
  163.        </xsl:variable>
  164.         <xsl:if test="$columnNumber < $maxColumnNo">
  165.             <xsl:variable name="nextColumnNodes" select="$columnNodes[position() != 1]" />
  166.             <xsl:choose>
  167.                 <xsl:when test="@table:number-columns-repeated">
  168.                     <xsl:apply-templates select="$nextColumnNodes[1]">
  169.                         <xsl:with-param name="columnNodes"           select="$nextColumnNodes" />
  170.                         <xsl:with-param name="currentColumnNumber"  select="$columnNumber" />
  171.                         <xsl:with-param name="maxColumnNo"           select="$maxColumnNo" />
  172.                         <xsl:with-param name="setIndex"              select="true()" />
  173.                     </xsl:apply-templates>
  174.                 </xsl:when>
  175.                 <xsl:otherwise>
  176.                     <xsl:apply-templates select="$nextColumnNodes[1]">
  177.                         <xsl:with-param name="columnNodes"           select="$nextColumnNodes" />
  178.                         <xsl:with-param name="currentColumnNumber"  select="$columnNumber + 1" />
  179.                         <xsl:with-param name="maxColumnNo"           select="$maxColumnNo" />
  180.                     </xsl:apply-templates>
  181.                 </xsl:otherwise>
  182.             </xsl:choose>
  183.         </xsl:if>
  184.     </xsl:template>
  185.  
  186.  
  187.     <!-- ************* -->
  188.     <!-- *** Rows  *** -->
  189.     <!-- ************* -->
  190.  
  191.  
  192.     <!-- Recursions are much faster when the stack size is small     -->
  193.     <xsl:template name="optimized-row-handling">
  194.         <xsl:param name="rowNodes" />
  195.         <xsl:param name="offset" select="0"/>
  196.         <xsl:param name="threshold" select="10"/>
  197.  
  198.         <xsl:variable name="rowCount" select="count($rowNodes)"/>
  199.         <xsl:choose>
  200.             <xsl:when test="$rowCount <= $threshold">
  201.                 <xsl:apply-templates select="$rowNodes[1]">
  202.                     <xsl:with-param name="rowNodes" select="$rowNodes" />
  203.                     <xsl:with-param name="offset" select="$offset" />
  204.                 </xsl:apply-templates>
  205.             </xsl:when>
  206.             <xsl:otherwise>
  207.                 <xsl:variable name="rowCountHalf" select="floor($rowCount div 2)"/>
  208.                 <xsl:variable name="rowNodesSetA" select="$rowNodes[position() <= $rowCountHalf]"/>
  209.                 <xsl:variable name="rowNodesSetB" select="$rowNodes[position() > $rowCountHalf]"/>
  210.                 <!-- to keep track of the rownumber, the repeteated rows have to kept into accounts -->
  211.                 <xsl:variable name="rowsCreatedByRepetition">
  212.                 <xsl:choose>
  213.                     <xsl:when test="$rowNodesSetA/@table:number-rows-repeated">
  214.                         <xsl:value-of select="sum($rowNodesSetA/@table:number-rows-repeated)
  215.                                             - count($rowNodesSetA/@table:number-rows-repeated)" />
  216.                     </xsl:when>
  217.                     <xsl:otherwise>0</xsl:otherwise>
  218.                     </xsl:choose>
  219.                 </xsl:variable>
  220.                 <xsl:choose>
  221.                     <xsl:when test="$rowCountHalf > $threshold">
  222.                         <xsl:call-template name="optimized-row-handling">
  223.                             <xsl:with-param name="rowNodes" select="$rowNodesSetA"/>
  224.                             <xsl:with-param name="offset" select="$offset" />
  225.                         </xsl:call-template>
  226.                         <xsl:call-template name="optimized-row-handling">
  227.                             <xsl:with-param name="rowNodes" select="$rowNodesSetB"/>
  228.                             <xsl:with-param name="offset" select="$offset + $rowCountHalf + $rowsCreatedByRepetition" />
  229.                         </xsl:call-template>
  230.                     </xsl:when>
  231.                     <xsl:otherwise>
  232.                         <xsl:apply-templates select="$rowNodesSetA[1]">
  233.                             <xsl:with-param name="rowNodes" select="$rowNodesSetA"/>
  234.                             <xsl:with-param name="offset" select="$offset" />
  235.                         </xsl:apply-templates>
  236.                         <xsl:apply-templates select="$rowNodesSetB[1]">
  237.                             <xsl:with-param name="rowNodes" select="$rowNodesSetB" />
  238.                             <xsl:with-param name="offset" select="$offset + $rowCountHalf + $rowsCreatedByRepetition" />
  239.                         </xsl:apply-templates>
  240.                     </xsl:otherwise>
  241.                 </xsl:choose>
  242.             </xsl:otherwise>
  243.         </xsl:choose>
  244.     </xsl:template>
  245.  
  246.     <!--
  247.         Rows as "table:table-row" might be grouped in
  248.         "table:table-header-rows" or "table:table-row-group"
  249.         This row-tree will be traversed providing each Row with it's
  250.         calculatedRowPosition and earlierRowNumber.
  251.         By this repeated empty rows might be neglected in the spreadsheetml output,
  252.         as the following row will notice the 'gap' and provide @ss:Index,
  253.         which results in filling up the gap by a row without style and content.
  254.  
  255.         In Excel created rows by ss:Index are 'default' rows.
  256.     -->
  257.     <xsl:template match="table:table-row">
  258.         <xsl:param name="earlierRowNumber" select="0" />
  259.         <xsl:param name="offset" />
  260.         <xsl:param name="calculatedRowPosition" select="$offset + 1" />
  261.         <xsl:param name="rowNodes" />
  262.  
  263.         <xsl:choose>
  264.             <xsl:when test="@table:number-rows-repeated > 1">
  265.                 <xsl:call-template name="write-table-row">
  266.                     <xsl:with-param name="earlierRowNumber"  select="$earlierRowNumber" />
  267.                     <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  268.                 </xsl:call-template>
  269.                 <xsl:if test="@table:number-rows-repeated > 2 and table:table-cell/@office:value-type">
  270.                     <!-- In case a cell is being repeated, the cell will be created
  271.                     in a variabel, which is as many times given out, as being repeated -->
  272.                     <xsl:variable name="tableRow">
  273.                         <xsl:call-template name="write-table-row" />
  274.                     </xsl:variable>
  275.                     <xsl:call-template name="repeat-write-table-row">
  276.                         <xsl:with-param name="tableRow"     select="$tableRow" />
  277.                         <xsl:with-param name="repetition"   select="@table:number-rows-repeated - 1" />
  278.                    </xsl:call-template>
  279.                </xsl:if>
  280.             </xsl:when>
  281.             <xsl:otherwise>
  282.                 <xsl:call-template name="write-table-row">
  283.                     <xsl:with-param name="earlierRowNumber"  select="$earlierRowNumber" />
  284.                     <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  285.                 </xsl:call-template>
  286.             </xsl:otherwise>
  287.         </xsl:choose>
  288.  
  289.         <xsl:variable name="nextRowNodes" select="$rowNodes[position()!=1]" />
  290.         <xsl:choose>
  291.             <xsl:when test="@table:number-rows-repeated > 1">
  292.                 <xsl:apply-templates select="$nextRowNodes[1]">
  293.                     <xsl:with-param name="earlierRowNumber"  select="$calculatedRowPosition" />
  294.                     <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition + @table:number-rows-repeated" />
  295.                     <xsl:with-param name="rowNodes" select="$nextRowNodes" />
  296.                </xsl:apply-templates>
  297.             </xsl:when>
  298.             <xsl:otherwise>
  299.                 <xsl:apply-templates select="$nextRowNodes[1]">
  300.                     <xsl:with-param name="earlierRowNumber"  select="$calculatedRowPosition" />
  301.                     <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition + 1" />
  302.                     <xsl:with-param name="rowNodes" select="$nextRowNodes" />
  303.                 </xsl:apply-templates>
  304.             </xsl:otherwise>
  305.         </xsl:choose>
  306.     </xsl:template>
  307.  
  308.     <xsl:template name="write-table-row">
  309.         <xsl:param name="earlierRowNumber" select="0" />
  310.         <xsl:param name="calculatedRowPosition" select="1" />
  311.  
  312.         <xsl:element name="Row">
  313.             <xsl:if test="@table:visibility = 'collapse' or @table:visibility = 'filter'">
  314.                 <xsl:attribute name="ss:Hidden">1</xsl:attribute>
  315.             </xsl:if>
  316.             <xsl:if test="not($earlierRowNumber + 1 = $calculatedRowPosition)">
  317.                 <xsl:attribute name="ss:Index"><xsl:value-of select="$calculatedRowPosition" /></xsl:attribute>
  318.             </xsl:if>
  319.  
  320.             <!-- writing the style of the row -->
  321.             <xsl:apply-templates select="@table:style-name" mode="table-row" />
  322.  
  323.             <xsl:variable name="rowProperties" select="key('styles', @table:style-name)/*" />
  324.             <xsl:if test="$rowProperties/@style:use-optimal-row-height = 'false'">
  325.                 <!-- default is '1', therefore write only '0' -->
  326.                 <xsl:attribute name="ss:AutoFitHeight">0</xsl:attribute>
  327.             </xsl:if>
  328.  
  329.             <xsl:variable name="height" select="$rowProperties/@style:row-height" />
  330.             <xsl:if test="$height">
  331.                 <xsl:attribute name="ss:Height">
  332.                     <!-- using the absolute height in point -->
  333.                     <xsl:call-template name="convert2pt">
  334.                         <xsl:with-param name="value" select="$height" />
  335.                     </xsl:call-template>
  336.                 </xsl:attribute>
  337.             </xsl:if>
  338.             <xsl:apply-templates select="table:table-cell[1]">
  339.                 <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  340.                 <xsl:with-param name="cellNodes"  select="table:table-cell" />
  341.             </xsl:apply-templates>
  342.         </xsl:element>
  343.     </xsl:template>
  344.  
  345.  
  346.     <xsl:template name="repeat-write-table-row">
  347.         <xsl:param name="tableRow" />
  348.         <xsl:param name="repetition" />
  349.  
  350.         <xsl:copy-of select="$tableRow" />
  351.         <xsl:if test="$repetition > 1">
  352.             <xsl:call-template name="repeat-write-table-row">
  353.                 <xsl:with-param name="tableRow"   select="$tableRow" />
  354.                 <xsl:with-param name="repetition"  select="$repetition - 1" />
  355.             </xsl:call-template>
  356.         </xsl:if>
  357.     </xsl:template>
  358.  
  359.  
  360.     <!-- ************** -->
  361.     <!-- *** Cells  *** -->
  362.     <!-- ************** -->
  363.  
  364.     <!-- Table cells are able to be repeated by attribute in StarOffice,
  365.          but not in Excel. If more cells are repeated -->
  366.     <xsl:template name="table:table-cell" match="table:table-cell">
  367.         <xsl:param name="calculatedCellPosition" select="1" /><!-- the later table position of the current cell  -->
  368.         <xsl:param name="calculatedRowPosition" /><!-- the later table position of the current row  -->
  369.         <xsl:param name="setIndex" select="false()" /> <!-- if not '0' @ss:Index used for neglecting repeteated empty cells -->
  370.         <xsl:param name="repetition" select="@table:number-columns-repeated" /> <!-- used for explicit writen out cells -->
  371.         <xsl:param name="repetitionCellPosition" select="$calculatedCellPosition" /><!-- during repetition formula needs exact cell positioning -->
  372.         <xsl:param name="nextMatchedCellPosition"><!-- the later table position of the next cell  -->
  373.         <xsl:choose>
  374.             <xsl:when test="not(@table:number-columns-repeated) and not(@table:number-columns-spanned)">
  375.                 <xsl:value-of select="$calculatedCellPosition + 1" />
  376.             </xsl:when>
  377.             <xsl:when test="not(@table:number-columns-spanned)">
  378.                 <xsl:value-of select="$calculatedCellPosition + @table:number-columns-repeated" />
  379.             </xsl:when>
  380.             <xsl:when test="not(@table:number-columns-repeated)">
  381.                 <xsl:value-of select="$calculatedCellPosition + @table:number-columns-spanned" />
  382.             </xsl:when>
  383.             <xsl:otherwise>
  384.                 <xsl:value-of select="$calculatedCellPosition + @table:number-columns-spanned * @table:number-columns-repeated" />
  385.             </xsl:otherwise>
  386.         </xsl:choose>
  387.         </xsl:param>
  388.         <xsl:param name="cellNodes" /><!-- cells to be handled  -->
  389.  
  390.         <xsl:choose>
  391.             <!-- in case a repetition took place -->
  392.             <xsl:when test="$repetition > 0">
  393.                 <xsl:choose>
  394.                     <!-- In case of no cell content (text, subelements, attribute, except repeated style) the ss:Index could be used -->
  395.                     <xsl:when test="not(text()) and not(*) and not(@*[name() != 'table:number-columns-repeated'])">
  396.                         <xsl:choose>
  397.                             <xsl:when test="count($cellNodes) = 1">
  398.                                 <xsl:call-template name="create-table-cell">
  399.                                     <xsl:with-param name="setIndex" select="true()" />
  400.                                     <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition - 1" />
  401.                                     <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  402.                                 </xsl:call-template>
  403.                             </xsl:when>
  404.                             <xsl:otherwise>
  405.                                 <xsl:apply-templates select="$cellNodes[2]">
  406.                                     <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
  407.                                     <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  408.                                     <xsl:with-param name="setIndex" select="true()" />
  409.                                     <xsl:with-param name="cellNodes" select="$cellNodes[position() != 1]" />
  410.                                 </xsl:apply-templates>
  411.                             </xsl:otherwise>
  412.                         </xsl:choose>
  413.                     </xsl:when>
  414.                     <!-- Fastest cell repetition by creating cell once and copying, works not for
  415.                             a) cells with formula (need of actual cell postition)
  416.                             b) cells, which start with ss:Index (as ss:Index is not allowed to be repeated) -->
  417.                     <xsl:when test="not(@table:formula) and not($setIndex)">
  418.                         <!-- In case a non-empty cell is being repeated, the cell will be created
  419.                             in a variabel, which is as many times given out, as being repeated -->
  420.                         <xsl:variable name="tableCell">
  421.                             <xsl:call-template name="create-table-cell">
  422.                                 <xsl:with-param name="setIndex" select="false()" /><!-- copied cells may not have indices -->
  423.                             </xsl:call-template>
  424.                         </xsl:variable>
  425.                         <xsl:call-template name="repeat-copy-table-cell">
  426.                             <xsl:with-param name="tableCell"   select="$tableCell" />
  427.                             <xsl:with-param name="repetition"  select="$repetition" />
  428.                        </xsl:call-template>
  429.                         <xsl:apply-templates select="$cellNodes[2]">
  430.                             <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
  431.                             <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  432.                             <xsl:with-param name="cellNodes" select="$cellNodes[position() != 1]" />
  433.                         </xsl:apply-templates>
  434.                     </xsl:when>
  435.                     <!-- explicit writing (instead of copying) of cell for the cases mentioned above -->
  436.                     <xsl:otherwise>
  437.                         <xsl:call-template name="create-table-cell">
  438.                             <xsl:with-param name="setIndex" select="$setIndex" /><!-- a possible Index will be created -->
  439.                             <xsl:with-param name="calculatedCellPosition" select="$repetitionCellPosition" />
  440.                             <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
  441.                         </xsl:call-template>
  442.                         <xsl:choose>
  443.                             <!-- as long there is a repetition (higher '1') stay on the same cell node  -->
  444.                             <xsl:when test="$repetition > 1">
  445.                                 <xsl:call-template name="table:table-cell">
  446.                                     <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
  447.                                     <xsl:with-param name="calculatedRowPosition" select="$calculatedRowPosition" />
  448.                                     <xsl:with-param name="repetitionCellPosition">
  449.                                         <xsl:choose>
  450.                                             <xsl:when test="@table:number-columns-spanned">
  451.                                                 <xsl:value-of select="$repetitionCellPosition + @table:number-columns-spanned" />
  452.                                             </xsl:when>
  453.                                             <xsl:otherwise>
  454.                                                 <xsl:value-of select="$repetitionCellPosition + 1"/>
  455.                                             </xsl:otherwise>
  456.                                         </xsl:choose>
  457.                                     </xsl:with-param>
  458.                                     <xsl:with-param name="nextMatchedCellPosition" select="$nextMatchedCellPosition" />
  459.                                     <xsl:with-param name="repetition" select="$repetition - 1" />
  460.                                     <xsl:with-param name="cellNodes" select="$cellNodes" />
  461.                                 </xsl:call-template>
  462.                             </xsl:when>
  463.                             <xsl:otherwise>
  464.                                 <xsl:apply-templates select="$cellNodes[2]">
  465.                                     <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
  466.                                     <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  467.                                     <xsl:with-param name="cellNodes" select="$cellNodes[position() != 1]" />
  468.                                 </xsl:apply-templates>
  469.                             </xsl:otherwise>
  470.                         </xsl:choose>
  471.                     </xsl:otherwise>
  472.                 </xsl:choose>
  473.             </xsl:when>
  474.             <xsl:otherwise>
  475.                 <!-- in case no repetition took place -->
  476.                 <xsl:choose>
  477.                     <!-- neglect en empty cells by using ss:Index Attribut  -->
  478.                     <xsl:when test="not(text()) and not(*) and not(@*)">
  479.                         <xsl:choose>
  480.                             <!-- if it is the last cell, write this cell -->
  481.                             <xsl:when test="count($cellNodes) = 1">
  482.                                 <xsl:call-template name="create-table-cell">
  483.                                     <xsl:with-param name="setIndex" select="true()" />
  484.                                     <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition - 1" />
  485.                                     <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  486.                                 </xsl:call-template>
  487.                             </xsl:when>
  488.                             <xsl:otherwise>
  489.                                 <xsl:apply-templates select="$cellNodes[2]">
  490.                                     <xsl:with-param name="setIndex" select="true()" />
  491.                                     <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
  492.                                     <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  493.                                     <xsl:with-param name="cellNodes" select="$cellNodes[position() != 1]" />
  494.                                 </xsl:apply-templates>
  495.                             </xsl:otherwise>
  496.                         </xsl:choose>
  497.                     </xsl:when>
  498.                     <xsl:otherwise>
  499.                         <!-- create cell and use/unset the ss:Index -->
  500.                         <xsl:call-template name="create-table-cell">
  501.                             <xsl:with-param name="setIndex" select="$setIndex" />
  502.                             <xsl:with-param name="calculatedCellPosition" select="$calculatedCellPosition" />
  503.                             <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  504.                         </xsl:call-template>
  505.                         <xsl:apply-templates select="$cellNodes[2]">
  506.                             <xsl:with-param name="calculatedCellPosition" select="$nextMatchedCellPosition" />
  507.                             <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  508.                             <xsl:with-param name="cellNodes" select="$cellNodes[position() != 1]" />
  509.                         </xsl:apply-templates>
  510.                     </xsl:otherwise>
  511.                 </xsl:choose>
  512.             </xsl:otherwise>
  513.         </xsl:choose>
  514.     </xsl:template>
  515.  
  516.     <!-- Copies the variable 'tableCell' to the output as often as 'repetition' -->
  517.     <xsl:template name="repeat-copy-table-cell">
  518.         <xsl:param name="tableCell" />
  519.         <xsl:param name="repetition" />
  520.  
  521.         <xsl:if test="$repetition > 0">
  522.             <xsl:copy-of select="$tableCell"/>
  523.             <xsl:call-template name="repeat-copy-table-cell">
  524.                 <xsl:with-param name="tableCell"   select="$tableCell" />
  525.                 <xsl:with-param name="repetition"  select="$repetition - 1" />
  526.             </xsl:call-template>
  527.         </xsl:if>
  528.     </xsl:template>
  529.  
  530.     <xsl:template name="create-table-cell">
  531.         <xsl:param name="setIndex" select="false()" />
  532.         <xsl:param name="calculatedCellPosition" />
  533.         <xsl:param name="calculatedRowPosition" />
  534.  
  535.         <xsl:element name="Cell" namespace="urn:schemas-microsoft-com:office:spreadsheet">
  536.             <xsl:if test="$setIndex">
  537.                 <xsl:attribute name="ss:Index">
  538.                     <xsl:value-of select="$calculatedCellPosition"/>
  539.                 </xsl:attribute>
  540.             </xsl:if>
  541.             <xsl:if test="@table:number-columns-spanned > 1">
  542.                 <xsl:attribute name="ss:MergeAcross">
  543.                     <xsl:value-of select="@table:number-columns-spanned - 1" />
  544.                 </xsl:attribute>
  545.             </xsl:if>
  546.             <xsl:if test="@table:number-rows-spanned > 1">
  547.                 <xsl:attribute name="ss:MergeDown">
  548.                     <xsl:value-of select="@table:number-rows-spanned - 1" />
  549.                 </xsl:attribute>
  550.             </xsl:if>
  551.             <xsl:variable name="link" select="descendant::text:a/@xlink:href" />
  552.             <xsl:if test="$link">
  553.                 <xsl:attribute name="ss:HRef">
  554.                     <xsl:value-of select="$link" />
  555.                 </xsl:attribute>
  556.             </xsl:if>
  557.             <xsl:if test="@table:style-name">
  558.                 <xsl:apply-templates select="@table:style-name" />
  559.             </xsl:if>
  560.             <xsl:apply-templates select="@table:formula">
  561.                 <xsl:with-param name="calculatedCellPosition" select="$calculatedCellPosition" />
  562.                 <xsl:with-param name="calculatedRowPosition"  select="$calculatedRowPosition" />
  563.             </xsl:apply-templates>
  564.  
  565.             <xsl:choose>
  566.                 <xsl:when test="*">
  567.                 <!-- in case it is not an empty cell
  568.  
  569.                   As the sequence of comment and data is opposite in Excel and Calc no match work here, in both comments exist only once
  570.                   Possible Table Content of interest: text:h|text:p|text:list  -->
  571.                     <xsl:if test="text:h | text:p | text:list">
  572.                         <xsl:variable name="valueType">
  573.                             <xsl:choose>
  574.                                 <xsl:when test="@office:value-type">
  575.                                     <xsl:value-of select="@office:value-type" />
  576.                                 </xsl:when>
  577.                                 <xsl:otherwise>string</xsl:otherwise>
  578.                             </xsl:choose>
  579.                         </xsl:variable>
  580.                         <xsl:call-template name="ss:Data">
  581.                             <xsl:with-param name="valueType" select="$valueType" />
  582.                             <xsl:with-param name="cellStyleName" select="@table:style-name" />
  583.                         </xsl:call-template>
  584.                     </xsl:if>
  585.  
  586.                     <xsl:if test="office:annotation">
  587.                         <xsl:element name="Comment">
  588.                             <xsl:if test="office:annotation/@office:author">
  589.                                 <xsl:attribute name="ss:Author"><xsl:value-of select="office:annotation/@office:author" /></xsl:attribute>
  590.                             </xsl:if>
  591.                             <xsl:if test="office:annotation/@office:display = 'true'">
  592.                                 <xsl:attribute name="ss:ShowAlways">1</xsl:attribute>
  593.                             </xsl:if>
  594.                             <!-- ss:Data is oblicatory, but not the same as the ss:Cell ss:Data child, as it has no attributes  -->
  595.                             <ss:Data xmlns="http://www.w3.org/TR/REC-html40">
  596.                                 <xsl:for-each select="office:annotation/text:p">
  597.                                     <xsl:choose>
  598.                                         <xsl:when test="*">
  599.                                             <!-- paragraph style have to be neglected due to Excel error,
  600.                                                 which does not allow shadowing their HTML attributes -->
  601.                                             <xsl:for-each select="*">
  602.                                                 <xsl:call-template name="style-and-contents" />
  603.                                             </xsl:for-each>
  604.                                         </xsl:when>
  605.                                         <xsl:when test="@text:style-name">
  606.                                             <xsl:call-template name="style-and-contents" />
  607.                                         </xsl:when>
  608.                                         <xsl:otherwise>
  609.                                             <!-- if no style is set, BOLD is set as default -->
  610.                                             <B>
  611.                                                 <xsl:call-template name="style-and-contents" />
  612.                                             </B>
  613.                                         </xsl:otherwise>
  614.                                     </xsl:choose>
  615.                                 </xsl:for-each>
  616.                             </ss:Data>
  617.                         </xsl:element>
  618.                     </xsl:if>
  619.                 </xsl:when>
  620.             </xsl:choose>
  621.         </xsl:element>
  622.     </xsl:template>
  623.  
  624.     <!-- comments are handled separately in the cell -->
  625.     <xsl:template match="office:annotation" />
  626.     <xsl:template match="dc:date" />
  627.  
  628.     <xsl:template name="ss:Data">
  629.         <!-- the default value is 'String' in the office -->
  630.         <xsl:param name="valueType" select="'string'" />
  631.         <xsl:param name="cellStyleName" />
  632.  
  633.         <xsl:choose>
  634.             <xsl:when test="descendant::*/@text:style-name">
  635.                 <xsl:choose>
  636.                     <xsl:when test="$valueType = 'string'">
  637.                         <ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">
  638.                             <xsl:apply-templates>
  639.                                 <xsl:with-param name="cellStyleName" select="$cellStyleName" />
  640.                             </xsl:apply-templates>
  641.                         </ss:Data>
  642.                     </xsl:when>
  643.                     <xsl:when test="$valueType = 'boolean'">
  644.                         <ss:Data ss:Type="Boolean" xmlns="http://www.w3.org/TR/REC-html40">
  645.                             <xsl:apply-templates>
  646.                                 <xsl:with-param name="cellStyleName" select="$cellStyleName" />
  647.                             </xsl:apply-templates>
  648.                         </ss:Data>
  649.                     </xsl:when>
  650.                     <xsl:when test="$valueType = 'date'">
  651.                         <ss:Data ss:Type="DateTime" xmlns="http://www.w3.org/TR/REC-html40">
  652.                             <xsl:apply-templates>
  653.                                 <xsl:with-param name="cellStyleName" select="$cellStyleName" />
  654.                             </xsl:apply-templates>
  655.                         </ss:Data>
  656.                     </xsl:when>
  657.                     <!-- float, time, percentage, currency (no 'Error' setting) -->
  658.                     <xsl:otherwise>
  659.                         <ss:Data ss:Type="Number" xmlns="http://www.w3.org/TR/REC-html40">
  660.                             <xsl:apply-templates>
  661.                                 <xsl:with-param name="cellStyleName" select="$cellStyleName" />
  662.                             </xsl:apply-templates>
  663.                         </ss:Data>
  664.                     </xsl:otherwise>
  665.                 </xsl:choose>
  666.             </xsl:when>
  667.             <xsl:otherwise>
  668.                 <xsl:element name="Data">
  669.                     <xsl:call-template name="ss:Type">
  670.                         <xsl:with-param name="valueType" select="$valueType" />
  671.                     </xsl:call-template>
  672.                 </xsl:element>
  673.             </xsl:otherwise>
  674.         </xsl:choose>
  675.     </xsl:template>
  676.  
  677.  
  678.     <xsl:template name="ss:Type">
  679.         <xsl:param name="valueType" select="'string'" />
  680.  
  681.         <xsl:choose>
  682.             <xsl:when test="$valueType = 'string'">
  683.                 <xsl:attribute name="ss:Type">String</xsl:attribute>
  684.                 <xsl:apply-templates select="*"/>
  685.             </xsl:when>
  686.             <xsl:when test="$valueType = 'boolean'">
  687.                 <xsl:attribute name="ss:Type">Boolean</xsl:attribute>
  688.                 <xsl:choose>
  689.                     <xsl:when test="@office:boolean-value = 'true'">1</xsl:when>
  690.                     <xsl:otherwise>0</xsl:otherwise>
  691.                 </xsl:choose>
  692.             </xsl:when>
  693.             <xsl:when test="$valueType = 'date' or $valueType = 'time'">
  694.                 <!-- issue in Excel: can not have an empty 'DateTime' cell -->
  695.                 <xsl:attribute name="ss:Type">DateTime</xsl:attribute>
  696.                 <!-- Gathering information of two StarOffice date/time attributes
  697.                 Excel always needs both informations in one attribute -->
  698.                 <xsl:choose>
  699.                     <xsl:when test="@office:date-value">
  700.                     <!-- office:date-value may contain time (after 'T')-->
  701.                         <xsl:choose>
  702.                             <xsl:when test="contains(@office:date-value, 'T')">
  703.                                 <!-- in case time is also part of the date -->
  704.                                 <xsl:value-of select="substring-before(@office:date-value, 'T')" />
  705.                                 <xsl:text>T</xsl:text>
  706.                                 <xsl:value-of select="substring-after(@office:date-value,'T')" />
  707.                                <xsl:if test="not(contains(@office:date-value,'.'))">
  708.                                     <xsl:text>.</xsl:text>
  709.                                 </xsl:if>
  710.                                 <xsl:text>000</xsl:text>
  711.                             </xsl:when>
  712.                             <xsl:when test="@office:time-value">
  713.                             <!-- conatains date and time (time will be evaluated later -->
  714.                                 <xsl:value-of select="@office:date-value" />
  715.                                 <xsl:text>T</xsl:text>
  716.                                 <xsl:choose>
  717.                                     <xsl:when test="@table:formula or contains(@office:time-value,',')">
  718.                                         <!-- customized number types not implemented yet -->
  719.                                         <xsl:text>00:00:00.000</xsl:text>
  720.                                     </xsl:when>
  721.                                     <xsl:otherwise>
  722.                                         <xsl:value-of select="translate(substring-after(@office:time-value,'PT'),'HMS','::.')" />
  723.                                         <xsl:if test="not(contains(@office:time-value,'S'))">
  724.                                             <xsl:text>.</xsl:text>
  725.                                         </xsl:if>
  726.                                         <xsl:text>000</xsl:text>
  727.                                     </xsl:otherwise>
  728.                                 </xsl:choose>
  729.                             </xsl:when>
  730.                             <xsl:otherwise>
  731.                                 <xsl:value-of select="@office:date-value" />
  732.                                 <xsl:text>T00:00:00.000</xsl:text>
  733.                             </xsl:otherwise>
  734.                         </xsl:choose>
  735.                     </xsl:when>
  736.                     <xsl:otherwise>
  737.                         <xsl:if test="@office:time-value">
  738.                             <xsl:text>1899-12-31T</xsl:text>
  739.                             <xsl:choose>
  740.                                 <xsl:when test="@table:formula or contains(@office:time-value,',')">
  741.                                     <!-- customized number types not implemented yet -->
  742.                                     <xsl:text>00:00:00.000</xsl:text>
  743.                                 </xsl:when>
  744.                                 <xsl:otherwise>
  745.                                     <xsl:value-of select="translate(substring-after(@office:time-value,'PT'),'HMS','::.')" />
  746.                                    <xsl:if test="not(contains(@office:time-value,'S'))">
  747.                                         <xsl:text>.</xsl:text>
  748.                                     </xsl:if>
  749.                                     <xsl:text>000</xsl:text>
  750.                                 </xsl:otherwise>
  751.                             </xsl:choose>
  752.                         </xsl:if>
  753.                     </xsl:otherwise>
  754.                 </xsl:choose>
  755.             </xsl:when>
  756.             <!-- float, percentage, currency (no 'Error' setting) -->
  757.             <xsl:otherwise>
  758.                 <xsl:attribute name="ss:Type">Number</xsl:attribute>
  759.                 <xsl:value-of select="@office:value" />
  760.             </xsl:otherwise>
  761.         </xsl:choose>
  762.     </xsl:template>
  763.  
  764.  
  765.     <!-- ******************** -->
  766.     <!-- *** Common Rules *** -->
  767.     <!-- ******************** -->
  768.  
  769.     <xsl:template match="*">
  770.         <xsl:param name="cellStyleName" />
  771.  
  772.         <xsl:call-template name="style-and-contents">
  773.             <xsl:with-param name="cellStyleName" select="$cellStyleName" />
  774.         </xsl:call-template>
  775.     </xsl:template>
  776.  
  777.     <!-- disabling draw:frames -->
  778.     <xsl:template match="draw:frame" />
  779.  
  780.     <xsl:template match="text:s">
  781.         <xsl:call-template name="write-breakable-whitespace">
  782.             <xsl:with-param name="whitespaces" select="@text:c" />
  783.         </xsl:call-template>
  784.     </xsl:template>
  785.  
  786.     <!--write the number of 'whitespaces' -->
  787.     <xsl:template name="write-breakable-whitespace">
  788.         <xsl:param name="whitespaces" />
  789.  
  790.         <xsl:text> </xsl:text>
  791.         <xsl:if test="$whitespaces >= 1">
  792.             <xsl:call-template name="write-breakable-whitespace">
  793.                 <xsl:with-param name="whitespaces" select="$whitespaces - 1" />
  794.             </xsl:call-template>
  795.         </xsl:if>
  796.     </xsl:template>
  797.  
  798.     <!-- allowing all matched text nodes -->
  799.     <xsl:template match="text()"><xsl:value-of select="." /></xsl:template>
  800.  
  801. </xsl:stylesheet>
  802.  
  803.